package com.example.administrator.newproject;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashMap;

import Adapter.WoFragListAdapter;


/**
 * A simple {@link android.support.v4.app.Fragment} subclass.
 */
public class WoFragment extends Fragment {
    private String mParams;
    public WoFragment newIntance(String params){
        WoFragment woFragment = new WoFragment();
        Bundle bun=new Bundle();
        bun.putString("user",params);
        woFragment.setArguments(bun);
        return woFragment;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if(getArguments()!=null){
            mParams=getArguments().getString("user");
        }
    }


    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_wo, container, false);
        final ListView woListView= (ListView) view.findViewById(R.id.wofrag_listview);
        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<>();
        HashMap<String, Object> map1 = new HashMap<String, Object>();
        HashMap<String, Object> map2 = new HashMap<String, Object>();
        HashMap<String, Object> map3 = new HashMap<String, Object>();
        HashMap<String, Object> map4 = new HashMap<String, Object>();
        HashMap<String, Object> map5 = new HashMap<String, Object>();
        HashMap<String, Object> map6 = new HashMap<String, Object>();
        HashMap<String, Object> map7 = new HashMap<String, Object>();
        HashMap<String, Object> map8 = new HashMap<String, Object>();
        HashMap<String, Object> map9 = new HashMap<String, Object>();
        if(mParams==null){

            map1.put("name","注册/登录"); map1.put("image",R.drawable.default_avtar);
        }else {
            map1.put("name",mParams); map1.put("image",R.drawable.default_avtar);

        }
        map2.put("name","我的钱包"); map2.put("image",R.drawable.qianjia);
        map3.put("name","浏览记录"); map3.put("image",R.drawable.rate_star_big_off_holo_dark);
        map4.put("name","我的好房宝"); map4.put("image",R.drawable.ic_menu_view);
        map5.put("name","我的好房贷"); map5.put("image",R.drawable.ic_menu_sort_by_size);
        map6.put("name","我的租金贷"); map6.put("image",R.drawable.ic_menu_notifications);
        map7.put("name","房事记录"); map7.put("image",R.drawable.ic_menu_paste_holo_light);
        map8.put("name","消息"); map8.put("image",R.drawable.ic_menu_start_conversation);
        map9.put("name","联系电话 4008681111-0"); map9.put("image",R.drawable.ic_menu_call);


        arrayList.add(map1);
        arrayList.add(map2);
        arrayList.add(map3);
        arrayList.add(map4);
        arrayList.add(map5);
        arrayList.add(map6);
        arrayList.add(map7);
        arrayList.add(map8);
        arrayList.add(map9);

        WoFragListAdapter listAdapter = new WoFragListAdapter(arrayList, getActivity(),getActivity().getResources());
        woListView.setAdapter(listAdapter);

        woListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
             switch (position){
                 case 0:

                     Intent in0 = new Intent();
                     in0.setClass(getActivity(),ZhuCeDengLuActivity.class);
                     startActivity(in0);
                     break;
                 case 1:


                     break;
                 case 2:
                     Intent in2 = new Intent();
                       in2.setClass(getActivity(),ShouCangActivity.class);
                        startActivity(in2);
                     break;
                 case 3:


                     break;
                 case 4:


                     break;
                 case 5:

                     break;
                 case 6:


                     break;
                 case 7:

                     Intent in7=new Intent();
                    in7.setClass(getActivity(),XiaoXiActivity.class);
                     getActivity().startActivity(in7);
                     break;
                 case 8:
                     Intent in8=new Intent();
                     in8.setAction(Intent.ACTION_CALL);
                     in8.setData(Uri.parse("tel:4008681111-0"));
                     getActivity().startActivity(in8);

                     break;
             }
            }
        });

        return view;
    }


}
